library(plotly)
## Warning: package 'plotly' was built under R version 3.4.4
## Loading required package: ggplot2
## Warning: package 'ggplot2' was built under R version 3.4.4
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
# chaneg color by variables
pal1= c("red", "blue", "green")
p1= plot_ly(data = mtcars,
x= ~wt, y=~mpg,
type="scatter",
mode= "markers",
marker = list(size=20),
color=~ as.factor(cyl),
colors=pal1
)
p1
## Warning: package 'bindrcpp' was built under R version 3.4.4
# ggplotly with ggplot2
d1000=diamonds[ sample(nrow(diamonds), 1000), ]
p2= ggplot(data = d1000,aes(x=carat, y=price))+
geom_point(aes(text=paste0("Clarity:", clarity, sep="")), size=5)+
geom_smooth(method = "loess")+
geom_smooth(aes(colour=cut, fill=cut))+
facet_wrap(.~cut)+
ggtitle("Carat vs Price by cut")
## Warning: Ignoring unknown aesthetics: text
ggplotly(p2)
## `geom_smooth()` using method = 'loess' and formula 'y ~ x'
# 3D plot
p3= plot_ly(data=mtcars,
x=~wt, y=~mpg, z=~disp,
type = "scatter3d",
mode="markers", color=~as.factor(cyl))
p3
# heat map
p4= matrix(rnorm(96), nrow = 8, ncol = 12)
colnames(p4) =seq(1:12)
rownames(p4)= c("A", "B","C","D","E","F","G","H")
p4
## 1 2 3 4 5 6
## A -0.9280540 -0.59569381 0.3578794 -0.02902635 1.473702174 0.04179372
## B -1.0695670 0.80277091 0.3044816 0.91253908 -1.186049485 -0.38114882
## C -0.7053919 0.35174253 -0.5208420 -0.86915022 -2.896206018 -0.15147830
## D 1.4518060 1.88820495 1.0234318 1.36643649 0.563057725 0.76237320
## E 0.2795364 -0.39228097 -0.5313030 0.04442323 0.938415301 0.61400501
## F -1.5391745 0.97715514 -1.2448520 1.07958552 -0.143467698 1.34644395
## G -0.7303643 -0.25220457 -0.6407321 -1.37920625 0.816771053 1.37236715
## H -0.9012414 -0.08444702 -0.7385315 -1.16985832 -0.002140703 1.06344052
## 7 8 9 10 11 12
## A 0.2941714 -0.4190390 -1.85186069 -0.5516550046 0.5829916 -1.5401162
## B 0.5399197 -1.2619382 0.91915589 -0.2921864193 -0.6150409 2.4282645
## C -1.4933592 0.2295914 -1.52515501 0.0008894371 0.3527065 1.4035583
## D 0.3654108 1.7809855 0.51465376 -0.3428011835 -1.3491561 0.6099407
## E 0.6671232 0.7584575 1.55473015 1.1986854957 -0.1503703 0.3300268
## F 0.3826486 0.8401439 0.03767941 -0.6669354198 1.7839178 0.7016681
## G 0.3345694 0.7565841 -0.55165156 0.5137519731 0.5432903 -1.2737165
## H 1.1092013 -0.3161841 0.48636393 0.1139127167 -1.9679238 -0.2543281
plot_ly(y= rownames(p4), x= colnames(p4),
z = p4, type = "surface", # type= "heatmap" for heatmap
title= "Heat of PCR plate")
## Warning: 'surface' objects don't have these attributes: 'title'
## Valid attributes include:
## 'type', 'visible', 'showlegend', 'legendgroup', 'opacity', 'name', 'uid', 'ids', 'customdata', 'hoverinfo', 'hoverlabel', 'stream', 'z', 'x', 'y', 'text', 'surfacecolor', 'cauto', 'cmin', 'cmax', 'colorscale', 'autocolorscale', 'reversescale', 'showscale', 'colorbar', 'contours', 'hidesurface', 'lightposition', 'lighting', '_deprecated', 'scene', 'xcalendar', 'ycalendar', 'zcalendar', 'idssrc', 'customdatasrc', 'hoverinfosrc', 'zsrc', 'xsrc', 'ysrc', 'textsrc', 'surfacecolorsrc', 'key', 'set', 'frame', 'transforms', '_isNestedKey', '_isSimpleKey', '_isGraticule'